package SquarePackage;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class Squaretest {

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		testSquare = new Square(200, 20);
		mergeTestSquare =  new Square(200, 60);

	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	public Square testSquare;
	public Square mergeTestSquare;


	@Test 
	public final void setTemperatureTest(){
		testSquare.setTemperature(200);
		assertEquals(200, testSquare.getTemp(),0);         
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setTemperatureTooHighTest(){
		testSquare.setTemperature(5001);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setTemperatureNegativeTest(){
		testSquare.setTemperature(-201);
	}
	@Test
	public final void setBorderLegalCaseTest(){
		testSquare.setBorder(3);
		assertEquals(true, testSquare.hasBorder(3));
		assertEquals(1, testSquare.numberOfBorders());
	}
	@Test
	public final void setBorderIllegalCaseTest(){
		testSquare.setBorder(7);
		testSquare.setBorder(0);
		testSquare.setBorder(-1);
		assertEquals(0, testSquare.numberOfBorders());
	}
	@Test
	public final void setBordersLegalTestCase(){
		testSquare.setBorders(4,5,3);
		assertTrue(testSquare.hasBorder(5));
		assertTrue(testSquare.hasBorder(3));
		assertTrue(testSquare.hasBorder(4));
		assertEquals(3, testSquare.numberOfBorders());
	}
	public final void setBordersIllegalTestCase(){
		testSquare.setBorders(4,5,3,0,-1,7,38);
		testSquare.setBorders(1,-9,-10000000,10000000,2,99);
		assertTrue(testSquare.hasBorder(5));
		assertTrue(testSquare.hasBorder(3));
		assertTrue(testSquare.hasBorder(4));
		assertTrue(testSquare.hasBorder(2));
		assertTrue(testSquare.hasBorder(1));
		assertEquals(5, testSquare.numberOfBorders());
	}
	@Test
	public final void setBordersMaximumOverflowTest(){
		testSquare.setBorders(1,2,3,4,5,6,1,2,4);
		assertEquals(6, testSquare.numberOfBorders());

	}
	@Test
	public final void removeBorderLegalCaseTest(){
		testSquare.setBorder(3);
		testSquare.removeBorder(3);
		assertEquals(0, testSquare.numberOfBorders());
		assertFalse( testSquare.hasBorder(3));
	}
	@Test
	public final void removeBordersLegalCaseTest(){
		testSquare.setBorders(4,5,6,3);
		testSquare.removeBorders(4,5);
		assertEquals(2, testSquare.numberOfBorders());
		assertFalse(testSquare.hasBorder(5));
		assertTrue( testSquare.hasBorder(3));
		assertFalse(testSquare.hasBorder(4));
		assertTrue(testSquare.hasBorder(6));
	}
	@Test
	public final void mergeWithNewTemperatureTest(){
		testSquare.setTemperature(50);
		testSquare.setHumidity(20);
		testSquare.setBorder(3);
		mergeTestSquare.setTemperature(100);
		mergeTestSquare.setHumidity(60);
		mergeTestSquare.setBorder(3);
		testSquare.mergeWith(3, mergeTestSquare);
		assertEquals(85, testSquare.getTemp(),0);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setWeightConstantIllegalCaseTooBigTest(){
		Square.setWeightConstant(0.5);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setWeightConstantIllegalCaseTooSmallTest(){
		Square.setWeightConstant(0);
	}
	@Test 
	public final void setWeightConstantLegalCasetest(){
		Square.setWeightConstant(0.30);
		assertEquals(0.3,Square.getWeightConstant(),0.00000001);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void mergeWithIllegalCaseNullTest(){
		testSquare.mergeWith(2,null);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void mergeWithIllegalCaseDirectionTest(){
		testSquare.setBorder(2);
		testSquare.mergeWith(2,mergeTestSquare);
	}
	@Test (expected = AssertionError.class)
	public final void setHumidityIllegalTest(){
		testSquare.setHumidity(-100);
		assertEquals(20,testSquare.getHumidity(),0.0000001);
	}
	@Test
	public final void getTempInKelvinTest(){
		assertEquals(473.15, testSquare.getTempInKelvin(testSquare.getTemp()),0);
	}
	@Test
	public final void getTempFahrenheitTest(){
		assertEquals(392, testSquare.getTempInFahrenheit(testSquare.getTemp()),0);
	}
	@Test   (expected = IllegalArgumentException.class)
	public final void setTemperatureIllegalCaseTest(){
		testSquare.setTemperature(500000);
	}
	@Test
	public final void isValidTemperatureTrueCaseTest(){
		assertTrue(testSquare.isValidTemperature(3000));
	}
	@Test
	public final void isValidTemperatureFalseCaseTooHighTest(){
		assertFalse(testSquare.isValidTemperature(5001));
	}
	@Test
	public final void isValidTemperatureFalseCaseTooLowTest(){
		assertFalse(testSquare.isValidTemperature(-201));
	}
	@Test
	public final void isValidHumidityLegalcaseTest(){
		assertTrue(testSquare.isValidHumidity(50));
	}
	@Test
	public final void isValidHumidityFalseTest(){
		assertFalse(testSquare.isValidHumidity(150));
	}

	@Test
	public final void isValidHumidityFalseTest2(){
		assertFalse(testSquare.isValidHumidity(-100));
	}    
	@Test
	public final void canHaveAsTemperatureDomainTrueCaseTest(){
		assertTrue(testSquare.canHaveAsTemperatureDomain(-200, 100));
	}
	@Test
	public final void canHaveAsTemperatureDomainTrueCaseTest2(){
		assertTrue(testSquare.canHaveAsTemperatureDomain(-200, 200));
	}
	@Test
	public final void canHaveAsTemperatureDomainFalseCaseTest(){
		assertFalse(testSquare.canHaveAsTemperatureDomain(200, -200));
	}
	public final void setTemperatureDomainTrueCaseTest() {
		testSquare.setTemperatureDomain(-150.0, 50.0);
		assertEquals(-150, testSquare.getMinimumTemp(), 0);
		assertEquals(50.0, testSquare.getMaximumTemp(),0);
	}
	@Test
	public final void setTemperatureDomainTrueCaseTest2() {
		testSquare.setTemperature(-200);
		testSquare.setTemperatureDomain(-200.0, -200.0);
		assertEquals(-200, testSquare.getMinimumTemp(), 0);
		assertEquals(-200, testSquare.getMaximumTemp(),0);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setTemperatureDomainFalseCaseTest() {
		testSquare.setTemperatureDomain(-100.0, -500.0);
	}
	@Test
	public final void coldDamageLimitCaseTest(){
		testSquare.setTemperature(-14);
		assertEquals(0, testSquare.coldDamage(), 0);
	}
	@Test
	public final void ColdDamageVeryColdTest(){
		testSquare.setTemperature(-200);
		assertEquals(19, testSquare.coldDamage(), 0);
	}
	@Test
	public final void ColdDamageNoDamageTest(){
		testSquare.setTemperature(100);
		assertEquals(0, testSquare.coldDamage(), 0);
	}
	@Test
	public final void HeatDamageLimitTest(){
		testSquare.setTemperature(49);
		assertEquals(0, testSquare.heatDamage(), 0);
	}
	@Test
	public final void HeatDamageNoDamageTest(){
		testSquare.setTemperature(-150);
		assertEquals(0, testSquare.heatDamage(), 0);
	}
	@Test
	public final void HeatDamageVeryHotTest(){
		testSquare.setTemperature(200);
		assertEquals(11, testSquare.heatDamage(), 0);
	}
	@Test
	public final void RustDamageLowHumidityTest(){
		testSquare.setHumidity(0.15);
		assertEquals(0, testSquare.rustDamage(), 0);
	}
	@Test
	public final void RustDamageHighHumidityTest(){
		testSquare.setHumidity(50.0);
		assertEquals(2, testSquare.rustDamage(), 0);
	}
	@Test
	public final void RustDamageLimitTest(){
		testSquare.setHumidity(36);
		assertEquals(0, testSquare.rustDamage(), 0);
	}
	@Test   (expected = IllegalArgumentException.class)
	public final void setHeat_Damage_ValuesIllegalAmount1Test(){
		Square.setHeat_Damage_Values(200, -10);
	}
	@Test   (expected = IllegalArgumentException.class)
	public final void setHeat_Damage_ValuesIllegalAmount2Test(){
		Square.setHeat_Damage_Values(200, 6000);
	}
	@Test
	public final void setHeat_Damage_ValuesLegalCaseTest(){
		Square.setHeat_Damage_Values(100, 50);
		assertEquals(100, Square.getHEAT_DAMAGE_TEMPERATURE(), 0);
		assertEquals(50, Square.getHEAT_DAMAGE_RATE(), 0);
	}
	@Test
	public final void setHumidityVeryLowLegalCaseTest(){
		testSquare.setHumidity(5);
		System.out.println(testSquare.getHumidityPercentage());
		assertEquals(5, testSquare.getHumidity(),0);
	}
	@Test
	public final void setHumidityLegalCaseTest1(){
		testSquare.setHumidity(12.3446);
		System.out.println(testSquare.getHumidityPercentage());
		assertEquals(12.34, testSquare.getHumidity(),0);
	}
	@Test
	public final void setHumidityLegalCaseTest2(){
		testSquare.setHumidity(12.5678);
		System.out.println(testSquare.getHumidityPercentage());
		assertEquals(12.57, testSquare.getHumidity(),0);
	}
	@Test
	public final void setHumidityLegalCaseTest3(){
		testSquare.setHumidity(0.1);
		System.out.println(testSquare.getHumidityPercentage());
		assertEquals(0.10, testSquare.getHumidity(),0);
	}
	@Test
	public final void setHumidityLegalCaseTest4(){
		testSquare.setHumidity(0);
		System.out.println(testSquare.getHumidityPercentage());
		assertEquals(0.00, testSquare.getHumidity(),0);
	}
	@Test
	public final void setSlipperyFirstScenarioTrueTest(){
		testSquare.setHumidity(100);
		assertTrue(testSquare.isSlippery());
	}
	@Test
	public final void setSlipperySecondScenarioTrueTest(){
		testSquare.setTemperature(-20);
		testSquare.setHumidity(60);
		assertTrue(testSquare.isSlippery());
	}
	@Test
	public final void setSlipperyThirdScenarioTrueTest(){
		testSquare.setMadeOfSlipperyMaterial(true);
		assertTrue(testSquare.isSlippery());
	}
	@Test
	public final void setSlipperyFalseTest(){
		testSquare.setMadeOfSlipperyMaterial(false);
		testSquare.setHumidity(0);
		testSquare.setTemperature(10);
		assertFalse(testSquare.isSlippery());
	}
	public final void mergeWithSimpleTemperatureTest(){
		testSquare.setHumidity(50);
		mergeTestSquare.setHumidity(50);
		testSquare.setTemperature(50);
		testSquare.setBorder(2);
		mergeTestSquare.setTemperature(100);
		mergeTestSquare.setBorder(2);
		testSquare.mergeWith(2,mergeTestSquare);
		assertEquals(75, testSquare.getTemp(),0);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setIllegalWeightConstantTooHighTest(){
		Square.setWeightConstant(0.5);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void setIllegalWeightConstantSmallerTest(){
		Square.setWeightConstant(0);
	}
	@Test 
	public final void setlegalWeightConstantTest(){
		Square.setWeightConstant(0.3);
		assertEquals(0.3,Square.getWeightConstant(),0);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void mergeWithIllegalCaseTest(){
		testSquare.mergeWith(2,null);
	}
	@Test (expected = IllegalArgumentException.class)
	public final void mergeWithIllegalCase2Test(){
		testSquare.setBorder(2);
		testSquare.mergeWith(2,mergeTestSquare);
	}
	@Test 
	public final void getBordersTest(){
		testSquare.setBorders(4,5,3);
		int[] leftArray = new int[3];
		leftArray[0]=3;
		leftArray[1]=4;
		leftArray[2]=5;
		assertArrayEquals(leftArray,testSquare.getBorders());
	}
	@Test (expected = AssertionError.class)
	public final void roundOffFalseTest(){
		assertEquals(30.43,testSquare.roundOff(30.438294),0.01);
	}
	@Test
	public final void roundOffTrueTest(){
		assertEquals(30.44, testSquare.roundOff(30.4382), 0.01);
	}
}